import os
from config_model import Config

class SingletonMeta(type):
    """
        自定义的单例模式，如：
        class your_class(metaclass=SingletonMeta):
            def __init__(self):
                print("__init__")
        当执行如下代码, 只会打印一行“__init__"
        your_class()
        your_class()
    """
    _instances = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(SingletonMeta, cls).__call__(*args, **kwargs)
        return cls._instances[cls]

def get_config() -> Config:
    return Config.parse_file(os.path.dirname(os.path.realpath(__file__)) + '/config.json')

if __name__ == "__main__":
    print(get_config())